//
//  CinemaViewController.m
//  UI14_豆瓣完整版
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "CinemaViewController.h"
#import "MyTableViewCell1.h"
#import "CinemaModel.h"

@interface CinemaViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *cinArr;
@property (nonatomic, retain) NSArray *dataArr;

@end

@implementation CinemaViewController

- (void)dealloc {
    [_cinArr release];
    [_dataArr release];
    [_tableView release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor cyanColor];
    
    self.title = @"影院";
    // 数据解析
    NSString *path = [[NSBundle mainBundle] pathForResource:@"cinema" ofType:@"plist"];
    self.dataArr = [NSArray arrayWithContentsOfFile:path];
    
    self.cinArr = [NSMutableArray array];
    
    for (NSDictionary *dic in _dataArr) {
        CinemaModel *model = [CinemaModel cinemaModel];
        [model setValuesForKeysWithDictionary:dic];
        [_cinArr addObject:model];
    }
    
    
    
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView release];
    
    // 注册重用池
    [_tableView registerClass:[MyTableViewCell1 class] forCellReuseIdentifier:@"cell"];
    
    
}



// 行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 160;
}

// 行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _cinArr.count;
}

// cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MyTableViewCell1 *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    CinemaModel *model = _cinArr[indexPath.row];
    cell.nameLabel.text = model.cinemaName;
    cell.addressLabel.text = model.address;
    cell.phoneLabel.text = model.telephone;
    
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
